<template>
	<div>
		<div class="publicpageview" id="publicpageview">
			<div style="text-align: center;font-weight: bold;margin-top: 20px;">非住宅房屋附加租金统计汇总表</div>
			<!-- <div style="display:flex;margin-top: 10px;flex-flow: row wrap" v-if="topContet">
				<div style="margin-left: 30px;">产别{{topContet.field1}}</div>
				<div style="margin-left: 30px;">管片{{topContet.field2}}</div>
				<div style="margin-left: 30px;">所号{{topContet.field8}}</div>
				<div style="margin-left: 30px;">地址{{topContet.field3}}</div>
				<div style="margin-left: 30px;">查询日期{{topContet.field4}}</div>
				<div style="margin-left: 30px;">调租日期{{topContet.field5}}</div>
			</div> -->
			<div style="display: flex;margin-top: 20px;box-sizing: border-box;">
				<div class="list4">所号</div>
				<div class="list7">
					超高
				</div>
				<div class="list2">
					<div class="list6">暖气</div>
					<div style="display: flex;">
						<div class="list5">计租面积（㎡）</div>
						<div class="list5">金额（元）</div>
					</div>
				</div>
				<div class="list2">
					<div class="list6">电梯</div>
					<div style="display: flex;">
						<div class="list5">部数</div>
						<div class="list5">金额（元）</div>
					</div>
				</div>
				<div class="list7">
					合计
				</div>
			</div>
			 <!-- v-for="(item,index) in list" :key="index" -->
			<div style="display: flex;box-sizing: border-box;" v-for="(item,index) in list" :key="index">
				<div class="list8">{{item.blockNo}}</div>
				<div class="list9">{{item.highMoney}}</div>
				<div class="list3">{{item.rentArea}}</div>
				<div class="list3">{{item.heatRent}}</div>
				<div class="list3">{{item.elevatorNum}}</div>
				<div class="list3">{{item.elevatorRent}}</div>
				<div class="list11">{{item.all}}</div>
			</div>
			<div style="display: flex;box-sizing: border-box;">
				<div class="list8">合计</div>
				<div class="list9">{{hejiObject.highMoney}}</div>
				<div class="list3">{{hejiObject.rentArea}}</div>
				<div class="list3">{{hejiObject.heatRent}}</div>
				<div class="list3">{{hejiObject.elevatorNum}}</div>
				<div class="list3">{{hejiObject.elevatorRent}}</div>
				<div class="list11">{{hejiObject.all}}</div>
			</div>
		</div>

		<button style="margin: 10px auto 0;display: block;" @click="handleout">打印非住宅房屋附加租金统计汇总表</button>
		
		<!-- <button style="margin: 10px auto 0;display: block;" v-print="printObj">打印附加租金分析表</button>
		<div id="loading" v-show="printLoading"></div> -->
	</div>
</template>

<script>
	import * as XLSX from 'xlsx'
	import dayjs from 'dayjs'
	import {
		houseAdminList,
		addRoom,
		roomDetails,
		updRoom,
		blockList,
		blockDetail
	} from '@/api/industry'
	export default {
		props: {
			blockobj: Object
		},
		name: 'zujintiaozhengguocheng',
		data() {
			return {
				printLoading: true,
				printObj: {
					id: "publicpageview",
					popTitle: '打印预览',
					extraCss: "https://cdn.bootcdn.net/ajax/libs/animate.css/4.1.1/animate.compat.css",
					beforeOpenCallback(vue) {
						console.log('打开之前')
					},
					openCallback(vue) {
						console.log('执行了打印')
					},
					closeCallback(vue) {
						console.log('关闭了打印工具')
					}
				},
				list: [],
				topContet: {},
				hejiObject: {
					highMoney: 0,
					rentArea: 0,
					heatRent: 0,
					elevatorNum: 0,
					elevatorRent: 0,
					all: 0,
				},
			}
		},
		computed: {},
		mounted() {
			console.log(this.blockobj)
			this.list = this.blockobj.notHouse2
			// this.topContet = this.blockobj.exportTou
			if (this.list) {
				this.list.forEach((item, index) => {
					this.hejiObject.highMoney = Number(this.hejiObject.highMoney) + Number(item.highMoney)
					this.hejiObject.rentArea = Number(this.hejiObject.rentArea) + Number(item.rentArea)
					this.hejiObject.heatRent = Number(this.hejiObject.heatRent) + Number(item.heatRent)
					this.hejiObject.elevatorNum = Number(this.hejiObject.elevatorNum) + Number(item.elevatorNum)
					this.hejiObject.elevatorRent = Number(this.hejiObject.elevatorRent) + Number(item.elevatorRent)
					this.hejiObject.all = Number(this.hejiObject.all) + Number(item.all)
				})
				console.log(this.hejiObject)
			}
		},

		methods: {
			handleout() {
				this.$confirm('此操作将导出该条内容，请确认是否继续操作？', '导出提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				})
				.then(() => {
					let list = this.list
					let outList = []
					this.list.forEach((item, index) => {
						outList.push({
							所号: item.blockNo,
							超高: item.highMoney,
							'暖气计租面积（㎡）': item.rentArea,
							'暖气金额（元）': item.heatRent,
							'电梯部数': item.elevatorNum,
							'电梯金额（元）': item.elevatorRent,
							合计: item.all,
						})
					})
					outList.push({
						所号: '合计',
						超高: this.hejiObject.highMoney,
						'暖气计租面积（㎡）': this.hejiObject.rentArea,
						'暖气金额（元）': this.hejiObject.heatRent,
						'电梯部数': this.hejiObject.elevatorNum,
						'电梯金额（元）': this.hejiObject.elevatorRent,
						合计: this.hejiObject.all,
					})
					// 获取表格数据
					const data = outList
					// 转换数据为工作表
					const worksheet = XLSX.utils.json_to_sheet(data)
					// 创建新的工作簿
					const workbook = XLSX.utils.book_new()
					// 将工作表添加到工作簿
					XLSX.utils.book_append_sheet(workbook, worksheet, 'Sheet1')
					// 导出Excel文件
					XLSX.writeFile(workbook, '非住宅房屋附加租金统计汇总表.xlsx')
				})
				.catch(() => {
					this.$message({
						type: 'info',
						message: '已取消导出'
					})
				})
			}
		},
	}
</script>

<style scoped>
	.publicpageview {
		width: 800px;
		height: auto;
		background-color: #fff;
		margin: 20px auto 0;
		overflow: hidden;
		box-sizing: border-box;
		padding: 20px;
		outline: 1px solid black;
	}

	.list1 {
		width: 100px;
		box-sizing: border-box;
		height: 30px;
		line-height: 30px;
		text-align: center;
		outline: 1px solid black;
	}

	.list2 {
		height: 40px;
		line-height: 30px;
		outline: 1px solid black;
		text-align: center;
		font-size: 12px;
	}

	.left {
		width: 25px;
		height: 360px;
		outline: 1px solid black;
		line-height: 180px;
		text-align: center;
		box-sizing: border-box;
	}

	.list3 {
		width: 80px;
		height: 20px;
		line-height: 20px;
		outline: 1px solid black;
		text-align: center;
		box-sizing: border-box;
		font-size: 12px
	}

	.list4 {
		font-size: 12px;
		width: 80px;
		height: 40px;
		line-height: 40px;
		outline: 1px solid black;
		text-align: center;
		box-sizing: border-box;
	}
	.list8{
		font-size: 12px;
		width: 80px;
		height: 20px;
		line-height: 20px;
		outline: 1px solid black;
		text-align: center;
		box-sizing: border-box;
	}

	.list7 {
		font-size: 12px;
		width: 150px;
		height: 40px;
		line-height: 40px;
		outline: 1px solid black;
		text-align: center;
		box-sizing: border-box;
	}
	.list11{
		font-size: 12px;
		width: 150px;
		height: 20px;
		line-height: 20px;
		outline: 1px solid black;
		text-align: center;
		box-sizing: border-box;
	}
	.list9{
		font-size: 12px;
		width: 150px;
		height: 20px;
		line-height: 20px;
		outline: 1px solid black;
		text-align: center;
		box-sizing: border-box;
	}

	.list5 {
		font-size: 12px;
		width: 80px;
		height: 20px;
		line-height: 20px;
		outline: 1px solid black;
		text-align: center;
		box-sizing: border-box;
	}

	.list6 {
		font-size: 12px;
		width: 100%;
		height: 20px;
		line-height: 20px;
		outline: 1px solid black;
		text-align: center;
		box-sizing: border-box;
	}
</style>